package main

import (
	"encoding/json"
	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/models/ledger"
	ledger2 "jlpay-sdk-go/pkg/jlpay/services/ledger"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 商户分账绑定示例
func merchRevBindDemo() {
	config := demo.CreateDemoConfig()
	merchconfService := ledger2.NewMerchconfService(config)

	// 构建请求参数
	requestData := map[string]interface{}{
		"org_code":   "50720711",
		"mch_id":     "849581183510017",
		"rev_mch_id": "849584307420004",
		"notify_url": "https://api.mch.weixin.qq.com/sns/notify",
		"source_ids": []string{
			"jlpay/2024-08-30/e22bc590f433418483626fded04f3362.png",
			"jlpay/2024-08-30/e22bc590f433418483626fded04f3363.png",
		},
	}

	request := ledger.NewMerchRevBindRequest()
	request.SetRawRequestMap(requestData)

	// 序列化请求数据并打印
	requestJSON, _ := json.Marshal(requestData)
	utils.Debugf("商户分账绑定请求数据: %s", string(requestJSON))

	// 发送请求
	response, err := merchconfService.BindMerchRev(request)
	if err != nil {
		utils.Errorf("商户分账绑定请求失败: %v", err)
		return
	}

	// 处理响应 - 使用BaseResponse接口的HandleResponse方法
	response.HandleResponse("商户分账绑定")
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 商户分账绑定示例 开始 =====")
	utils.Info("=============================")

	merchRevBindDemo()

	utils.Info("=============================")
	utils.Info("===== 商户分账绑定示例执行完毕 =====")
	utils.Info("=============================")
}
